"""导入百万级数据至mysql"""
import os
import pandas as pd
from sqlalchemy import create_engine
from project02.apps import app
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


@app.task
def task_to_sql():
    """
    :return:
    """
    xls_file = os.path.join(BASE_DIR, 'apps', 'new.xls')
    conn = create_engine('mysql+pymysql://root:Root@1234@localhost:3306/news?charset=utf8')
    print(conn)
    data = pd.read_excel(xls_file)
    data.to_sql('new', conn, index=False, if_exists='append')
    return 'Success'
